package pers.cz.compilation;


import javax.tools.SimpleJavaFileObject;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.URI;

/**
 * 为了让代码不从java文件中加载，直接从各种渠道得到字符代码，从字符中加载，需要自己继承 SimpleJavaFileObject 类来实现
 * @program: PostGirl-panent
 * @description: GenericJavaFileObject
 * @author: Cheng Zhi
 * @create: 2021-11-19 09:51
 **/
public class GenericJavaFileObject extends SimpleJavaFileObject {

    final private String content;

    public GenericJavaFileObject(String className, String content) throws Exception {
        super(URI.create("string:///" + className.replace('.', File.separatorChar)
                + Kind.SOURCE.extension), Kind.SOURCE);
        this.content = content;
    }

    @Override
    public CharSequence getCharContent(boolean ignoreEncodingErrors) {
        return content;
    }

}
